package com.fh.controller;/**
 * 描述:
 * Author:袁亚强
 * Date:2021/11/2216:46
 */

import com.fh.common.yyqData;
import com.fh.entity.po.Key;
import com.fh.entity.vo.Result;
import com.fh.service.KeyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * created by macro on 2021/11/22,
 */
@RestController
@RequestMapping("key")
public class KeyController {
    @Autowired
    private KeyService keyService;

    @PostMapping("queryByIdData")
    private yyqData queryByIdData(Integer id){
        if (id==null){
            return yyqData.error(400, "缺少参数");
        }
        return yyqData.success(keyService.queryByIdData(id));
    }

    @PostMapping("updateKey")
    private yyqData updateKey(Key key){
        if (key.getId()==null){
            return yyqData.error(400, "缺少参数");
        }
        keyService.updateKey(key);
        return yyqData.success("");
    }

    @PostMapping("addKey")
    private yyqData addKey(Key key){
        if (key.getTid()==null){
            return yyqData.error(400, "缺少参数");
        }
        if (key.getIsSku()==null){
            return yyqData.error(400, "缺少参数");
        }
        if (StringUtils.isEmpty(key.getName())){
            return yyqData.error(400, "缺少参数");
        }
        if (StringUtils.isEmpty(key.getNameID())){
            return yyqData.error(400, "缺少参数");
        }
        keyService.addKey(key);
        return yyqData.success("");
    }


    @GetMapping("queryPageData")
    public yyqData queryPageData(Result result){
        if(StringUtils.isEmpty(result.getPage())||StringUtils.isEmpty(result.getSize())){
            return yyqData.error(400, "缺少参数");
        }
        return yyqData.success(keyService.queryPageData(result));
    }

    @PostMapping("queryByName")
    public yyqData queryByName(String name,Integer tid){
        if (StringUtils.isEmpty(name)){
            return yyqData.error(400, "缺少参数");
        }
        if (tid==null){
            return yyqData.error(400, "缺少参数");
        }
        return yyqData.success(keyService.queryByName(name,tid));
    }
}
